// pages/dutyweekItemList/dutyweekItemList.js
var util = require('../../utils/util.js')
const app = getApp()


Page({

  /**
   * 页面的初始数据
   */
  data: {
    loading: 1,
    test: 0,
    invalidTitle: "提示",
    invalidArea: "请确保您已到达巡检地点！",
    noMore: true,
    content: [
      "是否有抄袭作业的行为", "班主任老师到岗前教室的学习氛围如何", "7点之前班主任老师是否已经到岗参加管理", "7:10之前各班是否已经完成卫生打扫工作"
    ],

    isshow: false,
    classname: [],
    categoryid: 0,
    classId: [],
    currentMacaddress: "00000",
    currentCheckpointId: 0,
    currentcheckAddress: "值周情况",
    currentcategoryid: 1,
    currentcategory:"",
    zhizhouErr: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      currentMacaddress: options.currentMacaddress,
      currentcheckAddress: options.currentcheckAddress,
      currentcategoryid: options.currentcategoryid,
      currentCheckpointId: options.currentcheckPointId,
      currentcategory:options.currentcategory,
      zhizhouErr:options.zhizhouErr,
    })
    console.log("==============", options);
    console.log("test1", this.data.zhizhouErr);
    console.log("test2", this.data.test);
    if(this.data.zhizhouErr==1){
      this.setData({
        loading: 0,
      })
    }
    console.log(options)
    this.showclasslist()
  },
  onShow: function () {
    wx.stopBeaconDiscovery()
    this.showclasslist()

  },
  //点击班级，开始搜配置巡巡查项
  bindWorkDetail: util.throttle(function (e) {
    console.log(e.currentTarget.dataset)
    let that = this
    wx.navigateTo({
      url: `/pages/dutyweekItemListdetail/dutyweekItemListdetail?classname=${e.currentTarget.dataset.classname}
      &classnameId=${e.currentTarget.dataset.classid}&categoryId=${that.data.currentcategoryid}
      &classNum=${e.currentTarget.dataset.num}&currentCheckpointId=${that.data.currentCheckpointId}
      &currentcategory=${that.data.currentcategory}&classisdone=${e.currentTarget.dataset.classisdone}
      &currentcheckAddress=${that.data.currentcheckAddress}`
    })
    that.setData({
      fromIndex: 0
    })
    // } 
    // else {
    //  值周没有查看历史页 不跳转
    // }
  }),
  showclasslist: function (e) {
    wx.request({
      url: app.zhizhouUrl + '/WeChat/weChatSystem/getTodayDutyWeekConditionByCategoryId',
      method: 'POST',
      data: {
        schoolId: parseInt(app.globalData.departmentId),
        categoryId: parseInt(this.data.currentcategoryid),
        macAddress: this.data.currentMacaddress,
        userId:parseInt(app.globalData.userId),
      },
      dataType: 'json',
      success: res => {
        console.log("2222", this.data.zhizhouErr)
         if(this.data.zhizhouErr==0){
          let doneclass = res.data.filter((item) => item.status != 2)
        let classdoneNum = doneclass.length || 0
        let classnoDone = res.data.length - classdoneNum
        this.setData({
          classname: res.data,
          classdoneNum: classdoneNum,
          realname: app.globalData.realname,
          classnoDone: classnoDone,
          loading: 0
        })
        console.log(
          "this.data.classname", this.data.classname
        );
        }
        
      }
    })
  },
})